package uit.uthuoc.fragment;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivityFragment extends ListFragment {

	public static final String LOG_ID = "uit.uthuoc.fragment.ListFragment";
	
	private MainActivityFragmentInterface mParentActivity;
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		
	    // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception
        try {
            mParentActivity = (MainActivityFragmentInterface) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement MainActivityFragmentInterface");
        }

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		if (position == 0) {
			mParentActivity.onSearchByDrugName();
		}
		if (position == 1) {
			mParentActivity.onSearchByMIMSClass();
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		ArrayList<String> arrayString = new ArrayList<String>();
		arrayString.add("Tìm theo tên thuốc");
		arrayString.add("Tìm theo phân loại");
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1
				, arrayString);
		
		setListAdapter(adapter);
		
	}
	
}
